<?php

namespace app\admin\model;

use think\Model;

class Category extends Model
{
    // 表名
    protected $name = 'category';
    protected static function init()
    {
        self::afterInsert(function ($row) {
            $row->save(['weigh' => $row['id']]);
        });
    }
    protected $category = [63=>['缴费服务','公共服务','办事服务'],118=>['家园服务中心']];

    public function createSiteNav($site_id){
        $category = $this->category;
        $categoryData = [];
        foreach ($category as $k=>$v){
            foreach ($v as $kk=>$vv){
                $data =
                    [
                        'site_id'=>$site_id,
                        'pid'=>$k,
                        'type'=>'navigation',
                        'name'=>$vv,
                        'nickname'=>$vv,
                        'status'=>'normal'
                    ];
                $categoryData[] = $data;
            }
        }
        if(!empty($categoryData)){
            $this->saveAll($categoryData);
        }
    }
    
}
